//preload switch image
var switch_off = new Image();
switch_off.src = "gifs/red_button_up.gif";
var switch_on = new Image();
switch_on.src = "gifs/red_button_dn.gif";
//preload LED images
var rled_off = new Image();
rled_off.src = "gifs/red_off.gif";
var rled_on = new Image();
rled_on.src = "gifs/red_on.gif";
var gled_off = new Image();
gled_off.src = "gifs/green_off.gif";
var gled_on = new Image();
gled_on.src = "gifs/green_on.gif";
var yled_off = new Image();
yled_off.src = "gifs/yellow_off.gif";
var yled_on = new Image();
yled_on.src = "gifs/yellow_on.gif";
//preload DIP switch
var dip_on = new Image();
dip_on.src = "gifs/dipa.gif";
var dip_off = new Image();
dip_off.src = "gifs/dipb.gif";
//preload 7 segment LEDs and DIP switch


//variables for DIP switch settings preset jam inputs.
var dip_a = 0;
var dip_b = 0;
var dip_c = 0;
var dip_d = 0;
//variable for 4029 BCD output the state of 4 yellow LEDs
var bcd_a = 0;
var bcd_b = 0;
var bcd_c = 0;
var bcd_d = 0;

//dip switch animation and setting of variables
function dipa_click(){
//
if (dip_a == 0)
{
dip_a = 1;
document.images.a_dip.src = dip_off.src;
}
else
{
dip_a = 0;
document.images.a_dip.src = dip_on.src;
}
//end
}
//
//
function dipb_click(){
//
if (dip_b == 0)
{
dip_b = 1;
document.images.b_dip.src = dip_off.src;
}
else
{
dip_b = 0;
document.images.b_dip.src = dip_on.src;
}
//end
}
//
//
function dipc_click(){
//
if (dip_c == 0)
{
dip_c = 1;
document.images.c_dip.src = dip_off.src;
}
else
{
dip_c = 0;
document.images.c_dip.src = dip_on.src;
}
//end
}
//
//
function dipd_click(){
//
if (dip_d == 0)
{
dip_d = 1;
document.images.d_dip.src = dip_off.src;
}
else
{
dip_d = 0;
document.images.d_dip.src = dip_on.src;
}
//end
}
//end dip switch settings
//
//
//
//preset or jam switch
var pre_set = 0;
function load_bcd(){
//
pre_set =1;
document.images.set_it.src = switch_on.src;
window.setTimeout("preset_off()",200);
//end
}
function preset_off(){
//
document.images.set_it.src = switch_off.src;
pre_set = 0;
bcd_a = dip_a;
bcd_b = dip_b;
bcd_c = dip_c;
bcd_d = dip_d;
light_bcd();
bcd_seven();
//end
}
//
//
//
//light the BCD leds 4049 output
function light_bcd(){
//
if (bcd_a == 0)
{
document.images.a_led.src = yled_off.src;
}
else
{
document.images.a_led.src = yled_on.src;
}
//
if (bcd_b == 0)
{
document.images.b_led.src = yled_off.src;
}
else
{
document.images.b_led.src = yled_on.src;
}
//
if (bcd_c == 0)
{
document.images.c_led.src = yled_off.src;
}
else
{
document.images.c_led.src = yled_on.src;
}
//
if (bcd_d == 0)
{
document.images.d_led.src = yled_off.src;
}
else
{
document.images.d_led.src = yled_on.src;
}
//end
}
//lighting 4 yellow leds done
//
//
//BCD to 7 segment decoder 4511
//preload rectangular green LED images
var grnh_off = new Image();
grnh_off.src = "gifs/grn_off.gif";
var grnh_on = new Image();
grnh_on.src = "gifs/grn_on.gif";
//
var grnv_off = new Image();
grnv_off.src = "gifs/grn_off_v.gif";
var grnv_on = new Image();
grnv_on.src = "gifs/grn_on_v.gif";
//
function bcd_seven(){
//
if (  (bcd_a&!bcd_b&!bcd_c&!bcd_d)|(!bcd_a&!bcd_b&bcd_c&!bcd_d)|(!bcd_a&bcd_b&bcd_c&!bcd_d)|(bcd_b&!bcd_c&bcd_d)|(bcd_c&bcd_d) )
{
document.images.a_seg.src = grnh_off.src;
}
else
{
document.images.a_seg.src = grnh_on.src;
}
//
if (  (bcd_a&!bcd_b&bcd_c&!bcd_d)|(!bcd_a&bcd_b&bcd_c&!bcd_d)|(bcd_b&!bcd_c&bcd_d)|(bcd_c&bcd_d)  )
{
document.images.b_seg.src = grnv_off.src;
}
else
{
document.images.b_seg.src = grnv_on.src;
}
//
if (  (!bcd_a&bcd_b&!bcd_c&!bcd_d)|(bcd_b&!bcd_c&bcd_d)|(bcd_c&bcd_d) )
{
document.images.c_seg.src = grnh_off.src;
}
else
{
document.images.c_seg.src = grnh_on.src;
}
//
if (  (bcd_a&!bcd_b&!bcd_c&!bcd_d)|(!bcd_a&!bcd_b&bcd_c&!bcd_d)|(bcd_a&bcd_b&bcd_c&!bcd_d)|(bcd_a&!bcd_b&!bcd_c&bcd_d)|(bcd_b&!bcd_c&bcd_d)|(bcd_c&bcd_d) )
{
document.images.d_seg.src = grnh_off.src;
}
else
{
document.images.d_seg.src = grnh_on.src;
}
//
if (  (bcd_a&!bcd_b&!bcd_c&!bcd_d)|(bcd_a&bcd_b&!bcd_c&!bcd_d)|(!bcd_a&!bcd_b&bcd_c&!bcd_d)|(bcd_a&!bcd_b&bcd_c&!bcd_d)|(bcd_a&bcd_b&bcd_c&!bcd_d)|(bcd_a&!bcd_b&!bcd_c&bcd_d)|(bcd_b&!bcd_c&bcd_d)|(bcd_c&bcd_d) )
{
document.images.e_seg.src = grnh_off.src;
}
else
{
document.images.e_seg.src = grnh_on.src;
}
//
if (  (bcd_a&!bcd_b&!bcd_c&!bcd_d)|(!bcd_a&bcd_b&!bcd_c&!bcd_d)|(bcd_a&bcd_b&!bcd_c&!bcd_d)|(bcd_a&bcd_b&bcd_c&!bcd_d)|(bcd_b&!bcd_c&bcd_d)|(bcd_c&bcd_d) )
{
document.images.f_seg.src = grnh_off.src;
}
else
{
document.images.f_seg.src = grnh_on.src;
}
//
if (  (!bcd_a&!bcd_b&!bcd_c&!bcd_d)|(bcd_a&!bcd_b&!bcd_c&!bcd_d)|(bcd_a&bcd_b&bcd_c&!bcd_d)|(bcd_b&!bcd_c&bcd_d)|(bcd_c&bcd_d) )
{
document.images.g_seg.src = grnh_off.src;
}
else
{
document.images.g_seg.src = grnh_on.src;
}
//
//end
}
//lighting 7 segment display done
//
//
//
//flip flop using 4093 for up/dn settings
var up_dn = 1;
function up_sw(){
//
document.images.up_it.src = switch_on.src;
window.setTimeout("set_up()",200);
//end
}
function set_up(){
//
document.images.up_it.src = switch_off.src;
if (up_dn == 0)
{
up_dn = 1;
document.images.up_led.src = gled_on.src;
document.images.dn_led.src = gled_off.src;
//
if (bcd_a&bcd_d)
{
document.images.dp_seg.src = co_on.src;
co_led = 1;
}
else
{
document.images.dp_seg.src = co_off.src;
co_led = 0;
}
//
}
//end
}
//
//
function dn_sw(){
//
document.images.dn_it.src = switch_on.src;
window.setTimeout("set_dn()",200);
//end
}
function set_dn(){
//
document.images.dn_it.src = switch_off.src;
if (up_dn == 1)
{
up_dn = 0;
document.images.dn_led.src = gled_on.src;
document.images.up_led.src = gled_off.src;
//
if (!bcd_a&!bcd_b&!bcd_c&!bcd_d)
{
document.images.dp_seg.src = co_on.src;
co_led = 1;
}
else
{
document.images.dp_seg.src = co_off.src;
co_led = 0;
}
//
}
//end
}
// up-down flip flop  done
//
//
//
//clock input NAND 4093 oscillator f=1/1.1RC
//100K*10uF*1.1 = 1100mS ie 550mS on and 550mS off
var clk_state = 0;
function clk_sw(){
//
if (clk_state == 0)
{
document.images.clk_it.src = switch_on.src;
clk_state = 1;
clk_low();
}
else
{
document.images.clk_it.src = switch_off.src;
clk_state = 0;
}
//end
}
//
function clk_low(){
//
document.images.clk_led.src = rled_off.src;
window.setTimeout("clk_high()",550);
}
function clk_high(){
//
document.images.clk_led.src = rled_on.src;
//this is the rising edge or positive edge so count
count_it();
if (clk_state == 1)
{
window.setTimeout("clk_low()",550);
}
}
//end
// clock  done
//
//
//
//counter 4029 here
function count_it() {

if  (pre_set == 0)
{
if (up_dn == 1)
{
//
if (bcd_a&bcd_d)
{
set_zero(); //decimal counter 0 comes after 9
document.images.dp_seg.src = co_off.src;
co_led = 0;
}
else
{
count_up();
}
//
}
else
{
//
if (!bcd_a&!bcd_b&!bcd_c&!bcd_d)
{
set_nine(); //decimal counter 9 comes after 0
document.images.dp_seg.src = co_off.src;
co_led = 0;
}
else
{
count_dn();
}
//
}
//
}
light_bcd();
bcd_seven();
//end
}
//
//dp image preload
var co_off = new Image();
co_off.src = "gifs/dp_off.gif";
var co_on = new Image();
co_on.src = "gifs/dp_on.gif";
//
var co_led = 0; //the dp led in seven segment shows carry over of 4029
//
//count up mode
function count_up() {
if (bcd_a == 0)
{
bcd_a = 1;
}
else
{
bcd_a = 0;
b_up();
}
//
if (bcd_a&bcd_d)
{
document.images.dp_seg.src = co_on.src;
co_led = 1;
}
//
//end
}
//
//
function b_up() {
if (bcd_b == 0)
{
bcd_b = 1;
}
else
{
bcd_b = 0;
c_up();
}
//end
}
//
//
function c_up() {
if (bcd_c == 0)
{
bcd_c = 1;
}
else
{
bcd_c = 0;
d_up();
}
//end
}
//
//
function d_up() {
if (bcd_d == 0)
{
bcd_d = 1;
}
else
{
bcd_d = 0;
}
//end
}
//
//
//reset to 0 after 9 count up
function set_zero(){
bcd_a = 0;
bcd_b = 0;
bcd_c = 0;
bcd_d = 0;
}
//
//
//
//set to 9 after 0 count down
function set_nine(){
bcd_a = 1;
bcd_b = 0;
bcd_c = 0;
bcd_d = 1;
}
//
//
//
//
//count down mode
function count_dn(){
if (bcd_a == 1)
{
bcd_a = 0;
}
else
{
bcd_a = 1;
b_dn();
}
//
if (!bcd_a&!bcd_b&!bcd_c&!bcd_d)
{
document.images.dp_seg.src = co_on.src;
co_led = 1;
}
//
//end
}
//
//
function b_dn() {
if (bcd_b == 1)
{
bcd_b = 0;
}
else
{
bcd_b = 1;
c_dn();
}
//end
}
//
//
function c_dn() {
if (bcd_c == 1)
{
bcd_c = 0;
}
else
{
bcd_c = 1;
d_dn();
}
//end
}
//
//
function d_dn() {
if (bcd_d == 1)
{
bcd_d = 0;
}
else
{
bcd_d = 1;
}
//end
}
//
//
//
//
//
//end of script
